package com.tian.controller;

import com.tian.pojo.Report;
import com.tian.pojo.Users;
import com.tian.pojo.bo.ReportBO;
import com.tian.pojo.bo.center.CenterUserBO;
import com.tian.pojo.vo.UsersVO;
import com.tian.service.ReportService;
import com.tian.utils.CookieUtils;
import com.tian.utils.JSONResult;
import com.tian.utils.JsonUtils;
import com.tian.utils.PagedGridResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @ApiOperation(value = "投诉",notes = "投诉",httpMethod = "POST")
    @PostMapping("insert")
    public JSONResult insert(
            @RequestParam String username,
            @RequestParam String mobile,
            @RequestBody ReportBO reportBO

    ){
        Report report = reportService.insertReport(username, mobile, reportBO);


        return JSONResult.ok(report);
    }

    @RequestMapping("/getReport")
    public JSONResult getReport(
            @RequestParam String userId,
            @RequestParam Integer page,
            @RequestParam Integer pageSize){
        if (StringUtils.isBlank(userId)){
            return JSONResult.errorMsg(null);
        }
        if (page==null){
            page=1;
        }
        if (pageSize==null){
            pageSize=10;
        }

        PagedGridResult gridResult = reportService.queryPagedReport(userId,page, pageSize);

        return JSONResult.ok(gridResult);

    }
}
